package com.aabte.lota.auth.auth.shiro;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Sha512Hash;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/4/5
 */
public class PasswordUtils {

  public static String salt() {
    return new SecureRandomNumberGenerator().nextBytes().toHex();
  }

  public static PasswordBO encryptPassword(String plainText, int hashIterations) {
    String salt = salt();
    String cipherText = encryptPassword(plainText, salt, hashIterations);
    return PasswordBO.builder().plainText(plainText).cipherText(cipherText).salt(salt).build();
  }

  public static String encryptPassword(String plainText, String salt, int hashIterations) {
    return new Sha512Hash(plainText, salt, hashIterations).toHex();
  }
}
